﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMainSite.Repositories;

namespace MyMainSite.Services
{
    /// <summary>
    /// Summary description for MetaWeblogImage
    /// </summary>
    public class MetaWeblogImage : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string name = context.Request.Params["name"];

            var image = MetaWeblogImageRepository.GetByName(name);

            if (image != null)
            {
                context.Response.Clear();
                context.Response.ContentType = image.MIMEType;
                context.Response.BinaryWrite(image.Data);

                context.Response.Flush();
            }
            else
            {
                context.Response.Write("Failed to find file.");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}